import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_profile/chilidview/myattention/my_attention_controller.dart';
import 'package:basic_profile/model/article_data_list.dart';
import 'package:basic_widgets/app_bar_widget.dart';
import 'package:basic_widgets/image_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import 'package:flutter/gestures.dart';
class MyAttentionPage extends GetView<MyAttentionController> {
  const MyAttentionPage({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: backAppbar(title: '${controller.title.value}'),
        backgroundColor: Colors.white,
        body: Container(
          padding: EdgeInsets.symmetric(horizontal: ScreenHelper.width(15)),
          child: Column(
            children: [
              buildTitleItem(),
              SizedBox(
                height: ScreenHelper.height(10),
              ),
              Expanded(
                child: SizedBox(
                  child: Obx(() => TabBarView(
                      controller: controller.tabController,
                      children: controller.titleDataList.value
                          .map<Widget>((e) => buildTodo())
                          .toList())),
                ),
              )
            ],
          ),
        ));
  }

  Widget buildTitleItem() {
    return Container(
      color: Colors.white,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Expanded(
            child: Obx(() => controller.titleDataList.isEmpty?EmptyBox(title: "暂无数据"): SizedBox(
                  height: 48,
                  child: TabBar(
                      controller: controller.tabController,
                      indicatorSize: TabBarIndicatorSize.label,
                      labelPadding: EdgeInsets.zero,
                      // indicatorPadding: EdgeInsets.only(
                      //     right: ScreenHelper.width(70),
                      //     left: ScreenHelper.width(10)),
                      padding: EdgeInsets.zero,
                      indicatorWeight: 1,
                      dragStartBehavior: DragStartBehavior.down,
                      indicatorColor: AppTheme.primyColor,
                      labelColor: AppTheme.dartTextColor,
                      labelStyle: TextStyle(
                          color: AppTheme.dartTextColor,
                          fontSize: ScreenHelper.sp(16)),
                      unselectedLabelColor: AppTheme.weakTextColor,
                      tabs: controller.titleDataList
                          .map<Widget>((item) => Align(
                                alignment: Alignment.center,
                                child: Tab(
                                  text: item.columnTitle ?? '',
                                ),
                              ))
                          .toList()),
                )),
          ),
        ],
      ),
    );
  }

  Widget buildTodo() {
    return GetBuilder<MyAttentionController>(
      id: 'articleList',
      builder: (controller) => controller.articleList.isEmpty
          ? EmptyBox(title: '暂无数据')
          : ListView.builder(
              itemBuilder: (context, index) {
                ArticleList articleData = controller.articleList[index];
                return GestureDetector(
                    onTap: () => Get.toNamed(AppRoutes.articleDetail,
                        arguments: {"id": articleData.id}),
                    child: articleItem(
                        title: articleData.title!,
                        imgUrl: articleData.imgUrl!));
              },
              shrinkWrap: true,
              itemCount: controller.articleList.length,
            ),
    );
  }

  // 文章Item
  Widget articleItem({required String title, required String imgUrl}) {
    return Card(
      elevation: 0,
      child: ListTile(
        title: Text(
          "${title}",
          style: TextStyle(
              color: AppTheme.dartTextColor, fontSize: ScreenHelper.sp(16)),
        ),
        trailing: circleImg(raduis: 4, width: 90, head: imgUrl),
      ),
    );
  }
}
